import { ApiProperty } from '@nestjs/swagger';
import { AuditStatus } from '../../common/enums';

/**
 * Base response DTO for authentication endpoints with common fields
 */
export class BaseAuthResponseDto {
  @ApiProperty({
    description: 'JWT access token',
    example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
  })
  accessToken: string;

  @ApiProperty({
    description: 'Refresh token for renewing access',
    example: 'a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
  })
  refreshToken: string;

  @ApiProperty({
    description: 'Token expiration time in seconds',
    example: 3600,
  })
  expiresIn: number;

  @ApiProperty({
    description: 'User ID',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  userId: string;
}

/**
 * Response DTO for admin login endpoint
 */
export class AdminAuthTokenResponseDto extends BaseAuthResponseDto {
  // Admin login doesn't need status field
}

/**
 * Response DTO for user login endpoint
 */
export class UserAuthTokenResponseDto extends BaseAuthResponseDto {
  @ApiProperty({
    description: 'Audit status',
    enum: AuditStatus,
    example: AuditStatus.PASS,
  })
  status: AuditStatus;
}

/**
 * Base response DTO for token renewal
 */
export class BaseTokenRenewalResponseDto {
  @ApiProperty({
    description: 'JWT access token',
    example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
  })
  accessToken: string;

  @ApiProperty({
    description: 'Token expiration time in seconds',
    example: 3600,
  })
  expiresIn: number;
}

/**
 * Response DTO for admin token renewal
 */
export class AdminTokenRenewalResponseDto extends BaseTokenRenewalResponseDto {
  // Admin token renewal doesn't need status field
}

/**
 * Response DTO for user token renewal
 */
export class UserTokenRenewalResponseDto extends BaseTokenRenewalResponseDto {
  @ApiProperty({
    description: 'Audit status',
    enum: AuditStatus,
    example: AuditStatus.PASS,
  })
  status: AuditStatus;
}

/**
 * Legacy response DTO for token renewal endpoint
 * @deprecated Use AdminTokenRenewalResponseDto or UserTokenRenewalResponseDto instead
 */
export class TokenRenewalResponseDto extends UserTokenRenewalResponseDto {
  // Keeping for backward compatibility
}

/**
 * User data DTO for register response
 */
export class UserDataDto {
  @ApiProperty({
    description: 'User ID',
    example: '123e4567-e89b-12d3-a456-426614174000',
  })
  id: string;

  @ApiProperty({
    description: 'Username',
    example: 'user@example.com',
  })
  username: string;

  @ApiProperty({
    description: 'User role',
    example: 'user',
  })
  role: string;

  @ApiProperty({
    description: 'Device serial number',
    example: 'DEVICE-123456',
  })
  deviceSerialNumber: string;

  @ApiProperty({
    description: 'Device ID (deprecated, use deviceSerialNumber instead)',
    example: 'device-123456',
    deprecated: true,
  })
  deviceId: string;

  @ApiProperty({
    description: 'Display name',
    example: 'John Doe',
    required: false,
  })
  displayName?: string;

  @ApiProperty({
    description: 'Phone number',
    example: '13812345678',
    required: false,
  })
  phone?: string;

  @ApiProperty({
    description: 'Creation timestamp',
    example: '2023-01-01T00:00:00.000Z',
    required: false,
  })
  createdAt?: Date;

  @ApiProperty({
    description: 'Last update timestamp',
    example: '2023-01-01T00:00:00.000Z',
    required: false,
  })
  updatedAt?: Date;
}

/**
 * Response DTO for register endpoint
 */
export class RegisterResponseDto {
  @ApiProperty({
    description: 'HTTP status code',
    example: 201,
  })
  statusCode: number;

  @ApiProperty({
    description: 'Response message',
    example: 'User registered successfully',
  })
  message: string;

  @ApiProperty({
    description: 'User data',
    type: UserDataDto,
  })
  data: UserDataDto;
}

/**
 * Generic message response DTO
 */
export class MessageResponseDto {
  @ApiProperty({
    description: 'Response message',
    example: 'Operation completed successfully',
  })
  message: string;
}

/**
 * Response DTO for logout endpoint
 */
export class LogoutResponseDto extends MessageResponseDto {
  @ApiProperty({
    description: 'Response message',
    example: 'Successfully logged out',
  })
  message: string;
}

/**
 * Response DTO for password reset request endpoint
 */
export class PasswordResetRequestResponseDto extends MessageResponseDto {
  @ApiProperty({
    description: 'Response message',
    example: 'If a user exists with this phone number, they will receive a verification code',
  })
  message: string;
}

/**
 * Response DTO for password reset confirmation endpoint
 */
export class PasswordResetConfirmResponseDto extends MessageResponseDto {
  @ApiProperty({
    description: 'Response message',
    example: 'Password has been reset successfully',
  })
  message: string;
}
